package org.zhenglide.oa.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.zhenglide.oa.entity.Employee;
import org.zhenglide.oa.entity.LeaveBill;
import org.zhenglide.oa.service.ILeaveBillService;

@Controller
@RequestMapping("/leaveBill")
public class LeaveBillController {
	
	@Autowired
    ILeaveBillService leaveBillService;
    @RequestMapping("/list")
	public String list(HttpServletRequest req){
    	Employee employee = (Employee)req.getSession().getAttribute("employee");
    	List<LeaveBill> leaveBillList = leaveBillService.getMyLeaveBillList(employee.getId());
    	req.setAttribute("list", leaveBillList);
    	return "leaveBill/list";
	}
    @RequestMapping("/save")
   	public String save(LeaveBill leaveBill,HttpServletRequest req){
    	
//    	System.out.println(leaveBill.getContent());
    	Employee employee = (Employee)req.getSession().getAttribute("employee");
    	leaveBill.setUserId(employee.getId());
    	leaveBill.setState(0);
    	leaveBill.setLeaveDate(new Date());
       leaveBillService.saveOrUpdate(leaveBill);
       
       	return "redirect:/leaveBill/list";
   	}
    @RequestMapping("/delete")
   	public String delete(Integer id,HttpServletRequest req){
    	if(id!=null) {
    		leaveBillService.removeById(id);
    	}
       
    	return "redirect:/leaveBill/list";
   	}
    @RequestMapping("/input")
   	public String input(Integer id,HttpServletRequest req){
    	if(id!=null) {
    		 LeaveBill leaveBill = leaveBillService.getById(id);
    		 req.setAttribute("leaveBill", leaveBill);
    	}
       
       	return "leaveBill/input";
   	}
}
